<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>To do list</title>
  <style>
    .list{
      width: 500px;
      border: 1px solid #e8e8e8;
      border-radius: 12px;
      margin: auto;
      padding: 0 14px;
    }
    .list-item{
      display: flex;
      justify-content: space-between;
      padding: 20px 0;
      border-bottom: 1px solid #e8e8e8;
    }
    .list-item:last-child{
      border-bottom: 0;
    }
    .list-item.ok .list-item-name{
      text-decoration: line-through;
    }
    .list-item-name{
      color: #555;
    }
    .list-item-right{
      display: flex;
      align-items: center;
    }
    
    .list-item-ok{
      margin-right: 20px;
      font-size: 13px;
      color: green;
      cursor: pointer;
    }
    .list-item-remove{
      color: red;
      font-size: 13px;
      cursor: pointer;
    }
    .add-item{
      padding: 12px 0;
      display: flex;
    }
    .add-item-input{
      display: block;
      flex: 1;
      outline: none;
      height: 32px;
      border-radius: 12px;
      border: 1px solid #c7c7c7;
      margin-right: 20px;
      box-sizing: border-box;
      padding: 0 20px;
    }
    .add-item-btn{
      height: 32px;
      background: transparent;
      padding: 0 20px;
      border: 1px solid #c7c7c7;
      outline: none;
      border-radius: 12px;
    }
  </style>
</head>
<body>
  <div id="app">
    <div class="list">
      <div v-for="(item, index) in list" :key="index" v-if="item.del === false" class="list-item" :class="{ok: item.ok}">
        <div class="list-item-name">{{ item.title }}</div>
       
        <div class="list-item-right">
          <div v-if="!item.ok " class="list-item-ok" @click="onOk(item)">完成</div>
          <div class="list-item-remove" @click="onDel(item)">删除</div>
        </div>
      </div>
      <div class="add-item">
        <input v-model="itemTitle" type="text" class="add-item-input">
        <button class="add-item-btn" @click="onAdd">添加</button>
      </div>
    </div>
  </div>
  <script src="./vue.js"></script>
  <script>
    new Vue({
      el: '#app',
      data() {
        return {
          itemTitle: '',
          list: [
            {
              title: '今天要做的事情1',
              ok: false,
              del: false
            },
            {
              title: '今天要做的事情2',
              ok: false,
              del: false
            },
            {
              title: '今天要做的事情3',
              ok: false,
              del: false
            },
            {
              title: '今天要做的事情4',
              ok: false,
              del: false
            }
          ]
        }
      },
      methods: {
        onOk(item) {
          item.ok = true
        },
        onDel(item) {
          item.del = true
        },
        onAdd() {
          this.list.push({
            title: this.itemTitle,
            ok: false,
            del: false
          })
          this.itemTitle = ''
        }
      },
    })
  </script>
</body>
</html>